<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>openweather</title>
     <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f5f7fa;
            margin: 0;
            padding: 20px;
            color: #333;
        }
        .weather-container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }
        .weather-header {
            background: linear-gradient(135deg, #6b73ff 0%, #000dff 100%);
            color: white;
            padding: 20px;
            text-align: center;
        }
        .weather-header h2 {
            margin: 0;
            font-size: 24px;
        }
        .weather-date {
            font-size: 18px;
            opacity: 0.9;
            margin-top: 5px;
        }
        .weather-table {
            width: 100%;
            border-collapse: collapse;
        }
        .weather-table tr:nth-child(even) {
            background-color: #f8f9fa;
        }
        .weather-table tr:hover {
            background-color: #f1f3f5;
        }
        .weather-table th {
            text-align: left;
            padding: 15px 20px;
            background-color: #f1f3f5;
            font-weight: 600;
        }
        .weather-table td {
            padding: 12px 20px;
            border-bottom: 1px solid #e9ecef;
        }
        .weather-icon-day {
            width: 30px;
            height: 30px;
            vertical-align: middle;
            margin-right: 10px;
        }
        .temp-high {
            color: #ff6b6b;
            font-weight: bold;
        }
        .temp-low {
            color: #4dabf7;
            font-weight: bold;
        }
        .weather-description {
            display: flex;
            align-items: center;
        }
    </style>
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --text-color: #333;
            --light-bg: #f8f9fa;
            --card-bg: #ffffff;
            --border-color: #e9ecef;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: var(--light-bg);
            margin: 0;
            padding: 20px;
            color: var(--text-color);
        }

        .container {
            max-width: 1000px;
            margin: 0 auto;
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
        }

        .header h1 {
            color: var(--primary-color);
            margin-bottom: 10px;
        }

        .date-selector {
            display: flex;
            justify-content: center;
            margin-bottom: 20px;
            gap: 10px;
        }

        .date-btn {
            padding: 8px 16px;
            background-color: var(--card-bg);
            border: 1px solid var(--border-color);
            border-radius: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .date-btn:hover {
            background-color: var(--primary-color);
            color: white;
        }

        .date-btn.active {
            background-color: var(--primary-color);
            color: white;
            border-color: var(--primary-color);
        }

        .hourly-forecast {
            display: flex;
            overflow-x: auto;
            padding: 20px 0;
            gap: 15px;
            scrollbar-width: thin;
            scrollbar-color: var(--primary-color) var(--light-bg);
        }

        .hourly-forecast::-webkit-scrollbar {
            height: 8px;
        }

        .hourly-forecast::-webkit-scrollbar-track {
            background: var(--light-bg);
            border-radius: 10px;
        }

        .hourly-forecast::-webkit-scrollbar-thumb {
            background-color: var(--primary-color);
            border-radius: 10px;
        }

        .hour-card {
            min-width: 120px;
            background-color: var(--card-bg);
            border-radius: 12px;
            padding: 15px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            text-align: center;
            flex-shrink: 0;
            transition: transform 0.3s ease;
        }

        .hour-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
        }

        .hour-time {
            font-weight: bold;
            margin-bottom: 10px;
            font-size: 16px;
        }

        .weather-icon {
            width: 50px;
            height: 50px;
            margin: 5px auto;
        }

        .hour-temp {
            font-size: 20px;
            font-weight: bold;
            margin: 10px 0;
        }

        .hour-details {
            font-size: 12px;
            color: #666;
            margin-top: 5px;
        }

        .detail-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 3px;
        }

        .detail-label {
            font-weight: bold;
        }

        .current-weather {
            background-color: var(--card-bg);
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 30px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .current-main {
            display: flex;
            align-items: center;
        }

        .current-temp {
            font-size: 48px;
            font-weight: bold;
            margin-right: 20px;
        }

        .current-details {
            text-align: right;
        }

        .current-description {
            font-size: 18px;
            margin-bottom: 5px;
        }

        @media (max-width: 768px) {
            .hour-card {
                min-width: 100px;
                padding: 12px;
            }

            .current-weather {
                flex-direction: column;
                text-align: center;
            }

            .current-main {
                margin-bottom: 15px;
                flex-direction: column;
            }

            .current-temp {
                margin-right: 0;
                margin-bottom: 10px;
            }

            .current-details {
                text-align: center;
            }
        }
    </style>
</head>
<body>
维度：<input type="text" name="latitude" id="latitude">
经度：<input type="text" name="latitude" id="longitude">
  <button onclick="sendLocation()">发送我的位置</button>
    <p id="demo"></p>


<div>

   {# {% for i in range(count)%}
    wellcome : {{user}}
    {%endfor%}
    {%if count == 10%}
    <div style="border:red 1px solid">等于10</div>
    {%elif count == 9%}
    <div style="border:red 1px solid">等于9</div>
    {%else%}
    <div style="border:red 1px solid">等于llllll</div>
    {%endif%} #}
    <div style="border:1px solid black">
        今天日期：{{data.current.dt}}
        <br/>
        今日天气：{{data.current.weather[0].description}}
        <br/>
        温度：{{data.current.temp}}
        <br/>
        湿度：{{data.current.humidity}}
        <br/>
    </div>
    <br/>
    <div>
        {%set hourly_data = data.hourly | safe %}
      <div class="hourly-forecast" id="hourlyForecast">
            {% if data.hourly | length > 0%}
                {%for hour in data.hourly%}
                    <div class="hour-card">
                        <div class="hour-time">{{hour.dt}}</div>
                    <img src="https://openweathermap.org/img/wn/{{hour.weather[0].icon}}@2x.png" alt="{{hour.weather.description}}" class="weather-icon">
                    <div class="hour-temp">{{hour.temp}}°C</div>
                    <div class="hour-details">
                        <div class="detail-row">
                            <span class="detail-label">湿度:</span>
                            <span>{{hour.humidity}} %</span>
                        </div>
                        <div class="detail-row">
                            <span class="detail-label">风速:</span>
                            <span>{{hour.wind_speed}} m/s</span>
                        </div>
                        <div class="detail-row">
                            <span class="detail-label">降水:</span>
                            <span>{{hour.get("pop")* 100}} %</span>
                        </div>
                    </div>
                    </div>
                {%endfor%}
            {%else%}
            <div>hourly 数据为空</div>
            {%endif%}
        </div>
    </div>
    <br>
    <div style="border:1px solid green">
        未来几天数据：
        <br/>
        {% if data.daily | length >0%}
            {% for day in data.daily %}
                <div class="weather-container">
        <div class="weather-header">
            <h2>天气预报</h2>
            <div class="weather-date">{{day.dt}}</div>
        </div>

        <table class="weather-table">
            <tr>
                <th colspan="2">基本信息</th>
            </tr>
            <tr>
                <td width="30%">天气状况</td>
                <td class="weather-description">
                    <!-- 这里可以添加天气图标 -->
                    <img src="https://openweathermap.org/img/wn/{{day.weather[0].icon}}@2x.png" alt="{{day.weather[0].description}}" class="weather-icon-day">
                    {{day.weather[0].description}}
                </td>
            </tr>
            <tr>
                <th colspan="2">温度信息</th>
            </tr>
            <tr>
                <td>白天温度</td>
                <td>{{day.temp.day}}°C</td>
            </tr>
            <tr>
                <td>夜晚温度</td>
                <td>{{day.temp.night}}°C</td>
            </tr>
            <tr>
                <td>最高温度</td>
                <td class="temp-high">{{day.temp.max}}°C</td>
            </tr>
            <tr>
                <td>最低温度</td>
                <td class="temp-low">{{day.temp.min}}°C</td>
            </tr>
            <tr>
                <th colspan="2">其他信息</th>
            </tr>
            <tr>
                <td>日出时间</td>
                <td>{{day.sunrise}}</td>
            </tr>
            <tr>
                <td>日落时间</td>
                <td>{{day.sunset}}</td>
            </tr>
            <tr>
                <td>湿度</td>
                <td>{{day.humidity}}%</td>
            </tr>
            <tr>
                <td>风速</td>
                <td>{{day.wind_speed}} m/s</td>
            </tr>
             <tr>
                <td>降雨概率</td>
                <td>{{day.get("pop") * 100}} %</td>
            </tr>
        </table>
    </div>
            {%endfor%}
        {% else%}
        <div>空数据</div>
        {%endif%}
    </div>

</div>

</body>


<script>
    function setInit(){
        const status = document.getElementById("demo");
         status.textContent="当前位置：纬度{{session["latitude"]}},经度{{session["longitude"]}}"
    };
    window.onload=setInit();
        function sendLocation() {
            const status = document.getElementById("demo");
            latitude=document.getElementById("latitude").value
            longitude=document.getElementById("longitude").value

            console.log(latitude,longitude)
            if (latitude != null && longitude != null) {
                status.textContent = "发送中...";

                sendToServer(latitude, longitude);


            } else {
                status.textContent = "您的浏览器不支持定位功能";
            }
        }

        function sendToServer(lat, lng) {
            fetch('/save_location', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ latitude: lat, longitude: lng })
            })
            .then(response => response.json())
            .then(data => {
                document.getElementById("demo").textContent =
                    `定位已保存！纬度: ${lat}, 经度: ${lng},请重新刷新页面`;
            });
        }
    </script>
</html>